package com.smt.ejb3.tutoria.client;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.smt.ejb3.tutoria.entitybean.jointable.Buyer;
import com.smt.ejb3.tutoria.entitybean.jointable.Seller;
import com.smt.ejb3.tutoria.entitybean.jointable.User;
import com.smt.ejb3.tutoria.service.MappingService;

public class UserClient {
	public static void main(String[] args) {
		
		User user = new User();
		user.setName("user");
		
		Seller s = new Seller();
		s.setName("seller");
		s.setSell("sell");
		
		Buyer b = new Buyer();
		b.setName("buyer");
		b.setBuy("buy");
		
		try {
			InitialContext ctx = new InitialContext();

			MappingService service = (MappingService) ctx
					.lookup("MappingServiceImpl/remote");
			/* Save user */
//			service.saveUser(user);
//			service.saveUser(s);
//			service.saveUser(b);
			/* Find Buyer */
//			Buyer buyer = service.findBuyer(3);
//			System.out.println(buyer.getName());
			/* Find User */
			User u = service.findUser(3);
			Buyer buyer = (Buyer)u;
			System.out.println(buyer.getName());
			
		} catch (NamingException ex) {
			ex.printStackTrace();
		}
	}
}
